package NWish.properties.other
{
	import NWish.FileSystem;
	import NWish.Misc;
	import NWish.NWEvent;
	import NWish.NWishEditor;
	import NWish.json.OrderDict;
	import NWish.properties.CustomPropertiesTypes;
	import NWish.properties.Properties;
	import NWish.properties.custom.CustomProperties;
	import NWish.properties.object3ds.Camera3DProperties;
	import NWish.properties.object3ds.Scene3DProperties;
	import NWish.properties.object3ds.View3DProperties;
	
	import NWish.Interface.ILogger;
	
	
	
	public class FileSystemProperties extends Properties 
	{
		private var _isImport;
		private var _file_name;
		
		public function FileSystemProperties(parent,file_name,isImport = false)
		{
			super(parent);
			
			_isImport = isImport;
			_file_name = file_name;
			
			var keys
			= 
				['sceneName'
				];
			addPropertieKeys('FileSystem',keys);
			
			
			var keysRead
			= 
				['fileNames'
				,'resRefCount'
				,'resPaths'
				];
			addPropertieKeys_read('FileSystem',keysRead);
			
			
			addPropertieKeys_save('FileSystem',['resPaths']);
			
		}
		
		override public function toString()
		{
			return 'FileSystem';
		}
		
		/*public function isClass(obj)
		{
			return Misc.isClass(obj,type);
		}*/
		
		override public function get type()
		{
			return FileSystem;
		}
		
		override public function save(fileSystem,toDict:OrderDict,subPropertiesType:Array = null,isChild = false)
		{
			//FileSystem
			super.save(fileSystem,toDict,[CustomProperties]);
			
			//
			if(fileSystem.view)
				new View3DProperties(null).save(fileSystem.view,toDict);
			
			
			//
			if(fileSystem.camera)
				new Camera3DProperties().save(fileSystem.camera,toDict,[CustomProperties]);
			
			
			//
			if(fileSystem.scene)
				new Scene3DProperties().save(fileSystem.scene,toDict);
		}
		
		override public function load(dict,fileSystem,scene,subPropertiesType:Array = null)
		{
			//fileSystem
			super.load1(dict,fileSystem,scene,[CustomProperties]);
			
			//
			var child_dict 		= dict[toString()];
			//var files 		= child_dict['fileNames'];
			//var resourcePath 	= child_dict['resourcePath'];
			var resPaths 		= child_dict['resPaths'];
			
			fileSystem.loadFiles(resPaths,complete);
			
			//
			function complete()
			{
				//view
				if(_isImport == false)
				{
					var view = new View3DProperties(_app).load(dict,null,null,null);
					var scene = view.scene;
					var camera = view.camera;
					
					//camera
					new Camera3DProperties().load(dict,camera,scene,[CustomProperties]);
					
					
					//scene
					new Scene3DProperties(_app).load(dict,scene,scene,null);
					
					
					//
					_app.rootSprite.dispatchEvent(new NWEvent(NWEvent.LOADED_SCENE,_file_name));
				}
				else
				{
					//scene
					var scene = _app.away3d.scene;
					new Scene3DProperties(_app).load(dict,scene,scene,null);
					
					_app.rootSprite.dispatchEvent(new NWEvent(NWEvent.LOADED_SCENE,_file_name));
				}
			}
		}
	}
	

}